package com.bite.blog.service;

import com.bite.blog.mapper.BlogMapper;
import com.bite.blog.mapper.UserInfoMapper;
import com.bite.blog.model.BlogInfo;
import com.bite.blog.model.UserInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Slf4j
@Service
public class UserService {
    @Autowired
    private UserInfoMapper userInfoMapper;
    @Autowired
    private BlogMapper blogMapper;

    public UserInfo selectByName(String userName) {
        return userInfoMapper.selectByName(userName);
    }

    public UserInfo selectById(Integer userId) {
        return userInfoMapper.selectById(userId);
    }

    public UserInfo getAuthorInfo(Integer blogId) {
        BlogInfo blogInfo = blogMapper.selectBlogById(blogId);
        if (blogInfo==null||blogInfo.getUserId()<=0){
            log.error("博客不存在或者博客作者信息不合法,bolgId: {}",blogId);
            return null;
        }
        Integer userId = blogInfo.getUserId();
        return userInfoMapper.selectById(userId);
    }
}
